var connection = require('../backjs/node_mysql.js')


function checkout() {
    var pwd1 = $('#newPwd_1').val()
    var pwd2 = $('#newPwd_2').val()
    var msg_blok = document.getElementById('div_msg')
    var msg_text = $('#error_msg')

    if (pwd1 == pwd2) {
        var data = { "newPwd": pwd1, 'userId': user.user_id}
        $.ajax({
            url: '/changePwd.html',
            type: 'post',
            data: data,
            success: function (data, status) {
                if (status == 'success') {
                    alert('修改成功！即将重新登陆。')
                    $.ajax({
                            url:'/loginout',
                            type:'get',
                            data: {},
                            async:false,
                            success: function(data,status){
                                if(status == 'success'){
                                    window.location.href = '/login'
                                }
                            },
                            error: function(data,status){
                                if(status == 'error'){
                                    window.location.href = '/login'
                                }
                            }
                        }
                    );
                }
            },
            error: function (data, status) {
                if (status == 'error') {
                    alert("修改失败！");
                }
            }
        });
    } else {
        msg_blok.style.display = 'inline'
        msg_text.html('两次输入的密码必须一致')
    }
}






